% for article
%
% by wanze
% LPPL LaTeX Public Project License
%
%

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{article}

%盒子填不满容忍？
%\hbadness=10000

%宏包编写基本命令。
%\def\hi{Hello, this is my own package}
%\let\myDate\date
%\newcommand\GoodBye[1][\bfseries]{{#1Good Bye}}


\newlength{\textpt}
\setlength{\textpt}{11pt}
%========基本必备的宏包========%
\RequirePackage{calc,float,multicol,moresize}
%\RequirePackage[onehalfspacing]{setspace}
\linespread{1.4}
%1.3 onehalfspacing
%试卷或需要文字紧凑的
%1.6 doublespacing

%===========加入目录 某章或某节=====%
\newcommand{\addsectoc}[1]{
        \phantomsection
        \addcontentsline{toc}{section}{#1}}

%===========全文基本格式==========%
\setlength{\parskip}{1.6ex plus 0.2ex minus 0.2ex}   %段落間距
\setlength{\parindent}{\textpt * \real{2}}


%=========页面设置=========%
\RequirePackage[a4paper, %a4paper size 297:210 mm
  bindingoffset=0mm,%裝訂線
  top=35mm,  %上邊距 包括頁眉
  bottom=30mm,%下邊距 包括頁腳
  inner=30mm,  %左邊距or inner
  outer=30mm,  %右邊距or  outer
  headheight=10mm,%頁眉
  headsep=15mm,%
  footskip=15mm,%
  marginparsep=0em, %旁註與正文間距
  marginparwidth=0em,includemp=true% 旁註寬度計入width%旁註寬度
  ]{geometry}

%color
\RequirePackage[table,svgnames]{xcolor}
\definecolor{bgcolor-0}{HTML}{CCFFCC}


%================字體================%
%设置数学字体
\RequirePackage{amssymb,amsmath}
\RequirePackage{fontspec}
%si unit
\RequirePackage{siunitx}
\sisetup{
math-micro = \text{μ},
text-micro = μ
}
%num命令两边加上空格 numb
\providecommand{\numb}[1]{{~\num{#1}~}}

\providecommand{\abs}[1]{\lvert#1\rvert}
\everymath{\displaystyle}

 %設置英文字體
\setmainfont[Mapping=tex-text]{DejaVu Serif}
\setsansfont[Mapping=tex-text]{DejaVu Sans}
\setmonofont[Mapping=tex-text]{DejaVu Sans Mono}

%中文環境
\RequirePackage[CJKnumber=true]{xeCJK}
\xeCJKsetup{PunctStyle=plain}
\setCJKmainfont[BoldFont=Adobe 黑体 Std,ItalicFont=Adobe 楷体 Std]
    {Adobe 宋体 Std}%影響rmfamily字體
\setCJKsansfont{Adobe 黑体 Std}%影響sffamily字體
\setCJKmonofont{Adobe 楷体 Std}%影響ttfamily字體

\RequirePackage{xltxtra} %put here to avoid some package option error. maybe this package is useless ?

%=============新的字符===========%
\newfontfamily{\libertine}[Scale=1.3]{Linux Libertine O}
\newfontfamily{\ubuntu}[Scale=3]{Ubuntu}
\RequirePackage{newunicodechar}
\newunicodechar{Ⓐ}{{\libertine{Ⓐ}}}
%\newunicodechar{Ⓑ}{{\libertine{Ⓑ}}}
%\newunicodechar{Ⓒ}{{\libertine{Ⓒ}}}
%\newunicodechar{Ⓓ}{{\libertine{Ⓓ}}}
%\newunicodechar{①}{{\libertine{①}}}
%\newunicodechar{②}{{\libertine{②}}}
%\newunicodechar{③}{{\libertine{③}}}
%\newunicodechar{④}{{\libertine{④}}}
%\newunicodechar{⑤}{{\libertine{⑤}}}
\newunicodechar{}{{\ubuntu{}}}

%%===============中文化=========%
\renewcommand\contentsname{目~录}
\renewcommand\listfigurename{插图目录}
\renewcommand\listtablename{表格目录}
\renewcommand\indexname{索~引}
\renewcommand\figurename{图}
\renewcommand\tablename{表}
\renewcommand\partname{部分}
\renewcommand\appendixname{附录}
\renewcommand\abstractname{摘要}
\renewcommand{\today}{\number\year 年\number\month 月\number\day 日}


%=======页眉页脚格式=========%
\RequirePackage{fancyhdr}   %頁眉頁腳
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{第\CJKnumber{\arabic{section}}节~~#1}{}}
\fancypagestyle{plain}{%
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyhf[FR]{\thepage}}
\pagestyle{plain}

%=========章節標題設計=========%
\RequirePackage{titlesec}
\setcounter{secnumdepth}{3}
%修改section
\titleformat{\section}{\Large\sffamily}{\thesection}{0.5em}{}
%修改subsection
\titleformat{\subsection}{\large\sffamily}{\thesubsection}{0.5em}{}
%修改subsubsection
\titleformat{\subsubsection}{\normalsize\sffamily}{\thesubsubsection}{0.5em}{}


%================目录===============%
%toc label to contents space   dynamic adjust
\RequirePackage{tocloft}%
\renewcommand{\numberline}[1]{%
  \@cftbsnum #1\@cftasnum~\@cftasnumb%
}

%==============超鏈接===============%
\RequirePackage[colorlinks=true,linkcolor=blue,citecolor=blue]{hyperref} %設置書簽和目錄鏈接等
\newcommand{\hlabel}[1]{\phantomsection \label{#1}}%某一小段的引用


%=================文字強調=========%
\RequirePackage{ulem} %下劃線,加點
\normalem%normal em , not instead of the uline

\DeclareRobustCommand*{\uwave}%波浪线稍微下移点。
{\bgroup \markoverwith{\lower5\p@\hbox{\sixly \char58}}\ULon}


\newcommand\reduline{\bgroup\markoverwith
    {\textcolor{red}{\rule[-0.5ex]{1em}{0.4pt}}}\ULon}

%modified udot command from the dotuline
\def\udot{\bgroup
  \UL@setULdepth
  \markoverwith{\begingroup
     \advance\ULdepth0.1ex
     \lower\ULdepth\hbox{\kern.25em . \kern.045em}%
     \endgroup}%
  \ULon}
\renewcommand\emshape{\color{red}}

%==================插入圖片=======%
\RequirePackage{wrapfig}
\RequirePackage{graphicx}
\graphicspath{{images/}}
%change the caption style a little like 1-1
\renewcommand{\thefigure}{\arabic{section}-\arabic{figure}}

\RequirePackage[export]{adjustbox}% 'export' is needed
\newenvironment{fig}[2][1]
    {\begin{figure}[H]
    \centering
    \includegraphics[scale=#1 , keepaspectratio,max width=0.95\linewidth]{#2}}
    {\end{figure}}

%==============插入表格========%
\RequirePackage{booktabs}
\renewcommand{\thetable}{\arabic{section}-\arabic{table}}
\RequirePackage{caption}
%\renewcommand{\arraystretch}{1.3}
%如果用setspace宏包而不是linespread调整行间距，那么才需要额外的表格行距拉大。
\RequirePackage{longtable}
\RequirePackage{array}
\newcolumntype{x}[1]{>{\centering\arraybackslash\hspace{0pt}}p{#1}}



%插入代码
\RequirePackage{fancyvrb}%
\fvset{frame=lines,tabsize=4 ,baselinestretch=1.8, fontsize=\footnotesize}

%minted
\RequirePackage{minted}%
\RequirePackage[minted]{tcolorbox}%
\tcbuselibrary{breakable}
\definecolor{codeback}{RGB}{240,240,240}
\definecolor{bashback}{RGB}{48,10,36}

\newtcblisting{tcbcode}[2][]{listing engine=minted,minted language=#2,minted options={fontsize=\footnotesize,frame=none},listing only,#1,breakable=true,colback=codeback,boxrule=0.4pt,boxsep=0pt}

\newtcblisting{tcbpython}[1][]{listing engine=minted,minted language=python,minted options={fontsize=\footnotesize,frame=none},listing only,#1,breakable=true,colback=codeback,boxrule=0.4pt,boxsep=0pt}

\newtcblisting{tcbbash}[1][]{listing engine=minted,minted style=native,minted language=bash,minted options={fontsize=\footnotesize,frame=none},listing only,#1,breakable=true,boxrule=0.4pt,colback=bashback,coltext=white}

\newtcbinputlisting{tcbinput}[3][]{listing engine=minted,minted language=#2,minted options={fontsize=\footnotesize,frame=none},listing only,#1,breakable=true,colback=blue!5!white,boxrule=0.4pt,boxsep=0pt,listing file={#3}}



%==========其他宏包===========%
\RequirePackage{chemfig} %化学 同时tikz制图宏包也加载了
\usetikzlibrary{calc}
\RequirePackage[version=3]{mhchem}

%========脚注=========%
\newcommand*\circled[1]{%
  \tikz[baseline=(char.base)]\node[shape=circle,draw,inner sep=0.4pt,minimum size=4pt] (char) {#1};}
\newcommand*\circledarabic[1]{\circled{\arabic{#1}}}

\RequirePackage{perpage} %the perpage package
\MakePerPage{footnote} %the perpage package command

\renewcommand*{\thefootnote}{\protect\circledarabic{footnote}}

\renewcommand\@makefntext[1]
{\vspace{5pt}
\noindent
\makebox[20pt][c]{\@makefnmark}
\fontsize{10pt}{12pt}\selectfont #1}

\setlength{\skip\footins}{20pt plus 10pt}
%main body 与脚注之间的距离

%===========旁注===========%
\newcommand{\notefont}{\itshape\fontsize{10pt}{10pt}\selectfont }
\newcommand{\sidenote}[1]{\marginpar{\notefont #1}}


%=====特殊的环境特殊的文字======%
%=========重新定义 quote=====%
\renewenvironment{quote}
{\list{}{\rightmargin\leftmargin %右间距等于左间距
\itemindent   2em
}\item\relax
\ttfamily}
{\endlist}

%重新定义quotation
\renewenvironment{quotation}
{\list{}{\rightmargin\leftmargin %右间距等于左间距
\itemindent 2em%item的缩进也就是第一段的缩进
\listparindent \itemindent %第二段的缩进
}%
\item\relax
\ttfamily}
{\endlist}

\RequirePackage{framed}

%======notecard环境 一种卡片式记忆环境====%
%推荐的颜色有：black olive blue orange brown pink cyan purple darkgray red gray teal green violet lightgray white lime magenta yellow 建议都调淡30。!30
%不过推荐一个文档内部一种类型使用一种，其他颜色也是可以的。
\newsavebox{\tempbox}
\newenvironment{notecard}[1][white]
 {\noindent\ignorespaces%
 \setlength{\fboxsep}{10pt}
  \newcommand{\tempcolor}{#1}
  \hfill
  \begin{lrbox}{\tempbox}%
  \begin{minipage}{20em}
    \setlength{\parindent}{20pt}
    \setlength{\parskip}{1.618ex}   %段落間距
}
 {
 \ignorespacesafterend%
  \end{minipage}%
  \end{lrbox}%
  \colorbox{\tempcolor}{\usebox{\tempbox}}}


\endinput


